<!DOCTYPE html>
<html>

	<head class="head">
		<meta charset="utf-8">
		<title>搜索</title>
		<script>
			//这里面是屏幕适配的所有源码 复制这里面粘贴即可 样式可随便写 这里屏幕最大宽度为750px

			fixLayout() //初始执行一次
			window.addEventListener("resize", fixLayout); //监测屏幕大小改变时触发fixLayout方法

			//fixLayout方法添加一个meta屏幕大小适配标签
			function fixLayout() {
				const width = window.screen.width; //屏幕的宽度；
				const fixW = 750; //设置750则所有屏幕宽度都为750px
				const scale = width / fixW; // scale比例,这个比例会根据你写的内容px大小对应乘以这个比例得到响应屏幕的真正px值
				const meta = document.createElement("meta")
				meta.setAttribute("name", "viewport")
				meta.setAttribute("content", `width=device-width, initial-scale=${scale},user-scalable=no`)

				if (document.head.childNodes[14]) document.head.removeChild(document.head.childNodes[14]);
				document.head.appendChild(meta)
			}
		</script>
		<link rel="stylesheet" id="swe" href="https://cdn.jsdelivr.net/npm/sweetalert2/dist/sweetalert2.min.css">
		<script src="https://cdn.jsdelivr.net/npm/sweetalert2/dist/sweetalert2.min.js"></script>
		<!-- <link rel="stylesheet" type="text/css" href="http://mishengqiang.com/sweetalert/css/sweetalert.css"> -->
		<link rel="stylesheet" href="css/search.css">
		<!-- <script type="text/javascript" src="http://mishengqiang.com/sweetalert/js/sweetalert-dev.js"></script> -->
		<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
	</head>
	<body>
		<div class="form-structor">
			<div class="head">
				<div class="head-img" id="returnSign"><img src="img/zjt.png"></div>
				<div class="title">锡林南路小学</div>
			</div>
			<div class="search-boxx">
				<div class="search-box">
					<div class="searchs"><img src="img/ss.png"></div>
					<input class="search-txt" type="text" placeholder="请输入查询地址" id="search">
					<div class="searchx" id="empty"><img src="img/X.png"></div>
					<button class="submit-btn" id="btn">Search</button>
				</div>
				<div class="student">学生地址查询结果<span id="tiao"></span></div>
				<div class="address" id="address">
				</div>
				<!-- <div class="student">历史查询结果</div>
				<div class="historyc" id="historyc"> -->
				</div>
			</div>
		</div>
	</body>
	<script src="js/js.js"></script>
	<script>
		! function() {
			if (/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == false) {
				location.href = 'searchpc.html';
			}
		}();
		var btn = document.getElementById("btn")
		var search = document.getElementById("search")
		var center = document.getElementById("centere")
		var namea = document.getElementById("namea")
		var address = document.getElementById("address")
		// var historyc = document.getElementById("historyc")
		var empty = document.getElementById("empty")
		var mo = function(e) {
			e.preventDefault();
		};
		function stop() {
			document.body.style.overflow = 'hidden';
			document.addEventListener("touchmove", mo, false); //禁止页面滑动
		}
		stop()
		
		//返回登录页
		$('#returnSign').click(function() {
			window.location.href = "index.html";
		});
		//清空		
		empty.onclick = function() {
			search.value = ''
			address.innerHTML = ''
			// historyc.innerHTML = ''
			$("#address").css("visibility", "hidden")
			// $("#historyc").css("visibility", "hidden");
		}
		
		var move=function(e){
		e.preventDefault && e.preventDefault();
		e.returnValue=false;
		e.stopPropagation && e.stopPropagation();
		return false;
		    }
		    var keyFunc=function(e){
		if(37<=e.keyCode && e.keyCode<=40){
		return move(e);
		}
		}
		    document.body.onkeydown=keyFunc;
		
		
		
		
		// 页面恢复
		$("input").on("blur",function(){
		    window.scroll(0,0);
		});
		//搜索	
		// var type = false
		btn.onclick = function() {
			address.innerHTML = '';
			tiao.innerText = ''
			// historyc.innerHTML = '';
			if (search.value == "") {
				Swal.fire({
					title: "请输入要查询地址",
					text: "", // 如果需要额外文本信息，可以在这里添加
					// type: "error", // SweetAlert2 9.0.0+ 使用 'error' 类型
					// icon: "error", // 如果使用 SweetAlert2 10.0.0+，使用 'icon' 属性代替 'type'
					confirmButtonText: "确 定"
				}).then((result) => {
					if (result.isConfirmed) {
						$("#btn").removeAttr("disabled");
					}
				});
			} else if (search.value.length < 4) {
				// type = false
				Swal.fire({
						title: "请输入大于3个字的正确地址信息",
						text: "", // 同上，如果需要可以添加额外文本信息
						// type: "error", // 同上
						// icon: "error", // 同上
						confirmButtonText: "确 定"
					}).then((result) => {
						if (result.isConfirmed) {
							$("#btn").removeAttr("disabled");
						}
					});
			} else {
				let url = `http://101.201.73.103:8001/api/bd/student/query/?addr=${encodeURIComponent(search.value)}`
				Ajax.get(url,
					function(res) {
						// type = false
						if (JSON.parse(res).code == -2) {
							Swal.fire({
									title: '重新登录',
									text: '登录状态失效',
									icon: 'warning', // 使用 icon 属性代替旧版本的 type 属性
									confirmButtonText: "确 定"
								}).then((result) => {
									if (result.isConfirmed) {
										window.location.href = "index.html";
									}
								});
						} else if (JSON.parse(res).code == -1) {
							Swal.fire({
									title: '未查询到相同地址',
									text: '',
									icon: 'info', // 因为没有指定 type，我这里使用 'info' 类型的图标
									confirmButtonText: "确 定"
								}).then((result) => {
									if (result.isConfirmed) {
										// 用户点击了确认按钮，执行 AJAX 请求
										// let purl = 'http://101.201.73.103:8001/api/bd/student/file';
										// let data = {
										// 	addr: search.value,
										// };

										// // 假设 Ajax.post 是一个自定义的 AJAX POST 请求函数
										// // 这里需要确保 Ajax.post 函数返回一个 Promise
										// Ajax.post(purl, JSON.stringify(data)).then(function(res) {
										// 	$("#btn").removeAttr("disabled");
										// 	// 其他操作...
										// }).catch(function(error) {
										// 	// 处理 AJAX 请求错误
										// 	console.error("AJAX 请求失败:", error);
										// });
									}
								});
						} else {
							
							let arr = JSON.parse(res).data
							var tiao = document.getElementById("tiao")
							tiao.innerText = `共计${arr.length}条`
							if (arr[0].query == true) {
								for (var i = 1; i <= arr.length; i++) {
									var item = arr[i - 1]
									// var centere = $('#historyc');
									centere.append(`
						<div class="center-box"><div class="center-img"><img src="img/yh1.png" ></div>提交人：${item.createuser}</div>
						<div class="center-box"><div class="center-img"><img src="img/sj1.png" ></div>提交时间：${getLocalTime.getLocalTime(item.createtime)}</div>
						<div class="center-box"><div class="center-img"><img src="img/dz1.png" ></div>提交地址：${item.addr}</div>`)
								}
								// $("#historyc").css("visibility", "visible");
								$("#btn").removeAttr("disabled");
							} else {
								for (var i = 1; i <= arr.length; i++) {
									var item = arr[i - 1]
									var centere = $('#address');
									centere.append(`<div class="center-xbox">
						<div class="center-box"><div class="center-img"><img src="img/yh1.png" ></div>${item.name}</div>
						<div class="center-box"><div class="center-img"><img src="img/sfz1.png" ></div>${item.cid}</div>
						<div class="center-box"><div class="center-img"><img src="img/dh1.png" ></div>${item.phone}</div>
						<div class="center-box"><div class="center-img"><img src="img/dz1.png" ></div>${item.addr}</div>
						<div class="center-box"></div>
						</div>`)
								}
								$("#address").css("visibility", "visible");
								// $("#historyc").css("visibility", "hidden");

							}
						}


					})
			}
		}
	</script>

</html>
